home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / ToolFrm.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.2 KB  |  322 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ToolFrm.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef TOOLFRM_H
  15. #include "ToolFrm.h"
  16. #endif
  17.  
  18. #ifndef DRAWPART_H
  19. #include "DrawPart.h"
  20. #endif
  21.  
  22. #ifndef CONSTANT_H
  23. #include "Constant.h"
  24. #endif
  25.  
  26. // ----- Part Layer -----
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWCONTXT_H
  33. #include "FWContxt.h"
  34. #endif
  35.  
  36. #ifndef FWITERS_H
  37. #include "FWIters.h"
  38. #endif
  39.  
  40. // ----- OS Layer -----
  41.  
  42. #ifndef FWPOINT_H
  43. #include "FWPoint.h"
  44. #endif
  45.  
  46. #ifndef FWRECT_H
  47. #include "FWRect.h"
  48. #endif
  49.  
  50. #ifndef FWRECSHP_H
  51. #include "FWRecShp.h"
  52. #endif
  53.  
  54. #ifndef FWLINSHP_H
  55. #include "FWLinShp.h"
  56. #endif
  57.  
  58. #ifndef FWRESOUR_H
  59. #include "FWResour.h"
  60. #endif
  61.  
  62. #ifndef FWEVENT_H
  63. #include "FWEvent.h"
  64. #endif
  65.  
  66. // ----- OpenDoc Includes -----
  67.  
  68. #ifndef SOM_ODTransform_xh
  69. #include <Trnsform.xh>
  70. #endif
  71.  
  72. // ----- Platform Includes -----
  73.  
  74. #if defined(FW_BUILD_MAC) & !defined(__TOOLUTILS__)
  75. #include <ToolUtils.h>
  76. #endif
  77.  
  78. #if defined(FW_BUILD_MAC) & !defined(__LOWMEM__)
  79. #include <LowMem.h>
  80. #endif
  81.  
  82. //========================================================================================
  83. // Runtime Informations
  84. //========================================================================================
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment odfdrawframes
  88. #endif
  89.  
  90. FW_DEFINE_AUTO(CToolFrame)
  91.     
  92. //========================================================================================
  93. // CLASS CToolFrame
  94. //========================================================================================
  95.  
  96. //----------------------------------------------------------------------------------------
  97. // CToolFrame::CToolFrame
  98. //----------------------------------------------------------------------------------------
  99.  
  100. CToolFrame::CToolFrame(Environment *ev, ODFrame* odFrame, FW_CPresentation* presentation, CDrawPart *drawPart) :
  101.     CFloatingWindowFrame(ev, odFrame, presentation, drawPart),
  102.     fDrawPart(drawPart),
  103.     fToolGrid(3, 2, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(2)), FW_CPoint(FW_IntToFixed(kToolCellSize), FW_IntToFixed(kToolCellSize)), FW_kFixedPos1),
  104.     fFillFrameGrid(1, 3, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(kFillFrameSelectorPos)), FW_CPoint(FW_IntToFixed(15), FW_IntToFixed(12)), FW_kFixed0)
  105. {
  106. }
  107.  
  108. //----------------------------------------------------------------------------------------
  109. // CToolFrame::~CToolFrame
  110. //----------------------------------------------------------------------------------------
  111.  
  112. CToolFrame::~CToolFrame()
  113. {
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. // CToolFrame::Draw
  118. //----------------------------------------------------------------------------------------
  119.  
  120. void CToolFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  121. {
  122.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  123.     vc.SetMapping(fMapping);
  124.     
  125.     EraseBackground(ev, vc);
  126.     
  127.     DrawTools(vc);
  128.     DrawColors(vc);
  129.  
  130.     FW_CRect rect(
  131.         FW_IntToFixed(2),
  132.         FW_IntToFixed(2 + kToolHeight + 3),
  133.         FW_IntToFixed(kToolWidth + 2),
  134.         FW_IntToFixed(2 + kToolHeight + 3 + kSelectorHeight));
  135.         
  136.     CWidget    widget(131);
  137.     widget.Render(vc, rect);
  138.  
  139.     DrawRenderVerb(vc, fDrawPart->GetRenderVerb(), FW_kRGBBlack);
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. // CToolFrame::DrawTools
  144. //----------------------------------------------------------------------------------------
  145.  
  146. void CToolFrame::DrawTools(FW_CGraphicContext& gc)
  147. {    
  148.     FW_CRect toolRect;
  149.     fToolGrid.GetExteriorGridRect(toolRect);
  150.  
  151.     CWidget    widget(128 + fDrawPart->GetRenderVerb() - 1);
  152.     widget.Render(gc, toolRect);
  153.  
  154.     InvertTool(gc, fDrawPart->GetTool(), TRUE);
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. // CToolFrame::DrawColors
  159. //----------------------------------------------------------------------------------------
  160.  
  161. void CToolFrame::DrawColors(FW_CGraphicContext& gc)
  162. {
  163.     FW_Fixed left = FW_IntToFixed(4);
  164.     FW_Fixed top = FW_IntToFixed(kToolsWindowHeight - kColorSelectorHeight - 4);
  165.     FW_CRect colorRect(left, top, left + FW_IntToFixed(kColorSelectorWidth), top + FW_IntToFixed(kColorSelectorHeight));
  166.     
  167.     FW_CColor color;
  168.     
  169.     FW_CRectShape rectShape(colorRect, FW_kFill);
  170.     
  171.     fDrawPart->GetFillColor(color);
  172.     rectShape.GetInk().SetForeColor(color);
  173.     rectShape.GetStyle().SetPattern(fDrawPart->GetFillPattern());
  174.     rectShape.Render(gc);            // fill
  175.     
  176.     fDrawPart->GetFrameColor(color);
  177.     rectShape.GetInk().SetForeColor(color);    
  178.     rectShape.GetStyle().SetPenSize(FW_IntToFixed(5));
  179.     rectShape.GetStyle().SetPattern(fDrawPart->GetFramePattern());
  180.     rectShape.SetRenderVerb(FW_kFrame);
  181.     rectShape.Render(gc);            // frame
  182. }
  183.  
  184. //------------------------------------------------------------------------------
  185. // CToolFrame::DoMouseDown
  186. //------------------------------------------------------------------------------
  187.  
  188. FW_Handled CToolFrame::DoMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  189. {
  190.     FW_CPoint where = theMouseEvent.GetLogicalMousePosition(ev, fMapping);
  191.         
  192.     unsigned long tool;
  193.     if (fToolGrid.FindCell(where, tool))
  194.     {
  195.         fDrawPart->SetTool(ev, kSelectTool + tool);
  196.         return FW_kHandled;
  197.     }
  198.     
  199.     unsigned long renderVerb;
  200.     if (fFillFrameGrid.FindCell(where, renderVerb))
  201.     {
  202.         fDrawPart->SetRenderVerb(ev, kFrameOnly + renderVerb);
  203.         return FW_kHandled;
  204.     }
  205.         
  206.     return FW_kNotHandled;
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. // CToolFrame::CheckTool
  211. //----------------------------------------------------------------------------------------
  212.  
  213. void CToolFrame::CheckTool(Environment *ev, unsigned short oldTool, unsigned short newTool)
  214. {
  215.     FW_CFrameFacetIterator ite(ev, this);
  216.     for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  217.     {
  218.         FW_CViewContext vc(ev, this, facet);
  219.         vc.SetMapping(fMapping);
  220.         InvertTool(vc, oldTool, FALSE);
  221.         InvertTool(vc, newTool, TRUE);
  222.     }
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. // CToolFrame::InvertTool
  227. //----------------------------------------------------------------------------------------
  228.  
  229. void CToolFrame::InvertTool(FW_CGraphicContext& gc, unsigned short theTool, FW_Boolean state)
  230. {
  231.     if (theTool>0)
  232.     {
  233.         FW_CRect rect;
  234.         fToolGrid.GetCellInterior(theTool - kSelectTool, rect);
  235.  
  236. #ifdef FW_BUILD_MAC
  237.         if (state)
  238.         {
  239.             FW_CInk ink(FW_kRGBDarkGray, FW_kRGBWhite, FW_kHilite);    
  240.             FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
  241.             ink.SetForeColor(FW_kRGBWhite);
  242.             ink.SetBackColor(FW_kRGBGray);    
  243.             FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
  244.             ink.SetForeColor(FW_kRGBGray);
  245.             ink.SetBackColor(FW_kRGBLightGray);    
  246.             FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
  247.         }
  248.         else
  249.         {
  250.             FW_CInk ink(FW_kRGBLightGray, FW_kRGBGray, FW_kHilite);    
  251.             FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
  252.             ink.SetForeColor(FW_kRGBGray);
  253.             ink.SetBackColor(FW_kRGBWhite);    
  254.             FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
  255.             ink.SetForeColor(FW_kRGBWhite);
  256.             ink.SetBackColor(FW_kRGBDarkGray);    
  257.             FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
  258.         }
  259. #endif
  260.  
  261. #ifdef FW_BUILD_WIN
  262. FW_UNUSED(state);
  263.         FW_CRectShape::RenderRect(gc, rect, FW_kFill, FW_kInvertInk);
  264. #endif
  265.     }    
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. // CToolFrame::CheckRenderVerb
  270. //----------------------------------------------------------------------------------------
  271.  
  272. void CToolFrame::CheckRenderVerb(Environment *ev, unsigned short oldRenderVerb, unsigned short newRenderVerb)
  273. {
  274.     FW_CFrameFacetIterator ite(ev, this);
  275.     for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  276.     {
  277.         FW_CViewContext vc(ev, this, facet);
  278.         vc.SetMapping(fMapping);
  279.         DrawRenderVerb(vc, oldRenderVerb, FW_kRGBLightGray);
  280.         DrawRenderVerb(vc, newRenderVerb, FW_kRGBBlack);
  281.         DrawTools(vc);
  282.     }
  283. }
  284.  
  285. //----------------------------------------------------------------------------------------
  286. // CToolFrame::DrawRenderVerb
  287. //----------------------------------------------------------------------------------------
  288.  
  289. void CToolFrame::DrawRenderVerb(FW_CGraphicContext& gc, unsigned short renderVerb, const FW_CColor& color)
  290. {
  291.     if (renderVerb>0)
  292.     {
  293.         FW_CRect rect;
  294.         fFillFrameGrid.GetCellInterior(renderVerb - kFrameOnly, rect);
  295.         rect.Offset(FW_kFixed0, FW_IntToFixed(4));
  296.         rect.Inset(FW_IntToFixed(2), FW_IntToFixed(2));
  297.         
  298.         FW_CStyle style(FW_IntToFixed(2));
  299.         FW_CInk ink(color);
  300.         FW_CLineShape::RenderLine(gc, 
  301.                                 FW_CPoint(rect.left + FW_kFixedPos1, rect.bottom),
  302.                                 FW_CPoint(rect.right, rect.bottom),
  303.                                 ink,
  304.                                 style);
  305.     }
  306. }
  307.  
  308. //----------------------------------------------------------------------------------------
  309. // CToolFrame::HandleNotification
  310. //----------------------------------------------------------------------------------------
  311.  
  312. void CToolFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
  313. {
  314. FW_UNUSED(notification);
  315.     FW_CFrameFacetIterator ite(ev, this);
  316.     for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  317.     {
  318.         FW_CViewContext vc(ev, this, facet);
  319.         vc.SetMapping(fMapping);
  320.         DrawColors(vc);
  321.     }
  322. }